package com.Listener;

import com.Bean.UserCounter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserCounter userCounter=(UserCounter) applicationContext.getBean("user-counter");
        userCounter.AddUser();
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserCounter userCounter=(UserCounter) applicationContext.getBean("user-counter");
        userCounter.DecUser();
    }
}
